package com.qf.agro.web.controller.sys;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;

import com.qf.agro.common.sys.ResultInfo;
import com.qf.agro.pojo.sys.SysLog;
import com.qf.agro.service.sys.SysLogService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @company：千锋教育
 * @author：zhy
 * @date：2023/6/29
 *
 * 用户的控制器
 */
@RestController
@RequestMapping("/sys/log")
public class SysLogController {

    @Autowired
    private SysLogService logService;


    /**
     * 分页查询用户列表
     * @return
     */
    @GetMapping("/page")
    public ResultInfo findPage(@RequestParam(value = "page",defaultValue = "1") Integer pageNum,
                               @RequestParam(defaultValue = "5") Integer pageSize, String name){
        //1.调用业务层查询
        Page<SysLog> page = logService.findPage(pageNum, pageSize, name);
        //2.返回
        return ResultInfo.success(page);
    }

    /**
     * 用户新增
     * @param sysLog
     * @return
     */
    @PostMapping
    public ResultInfo save(@RequestBody SysLog sysLog){
        //1.调用业务层新增
        logService.save(sysLog);
        //2.返回
        return ResultInfo.success(null);
    }




    /**
     * 禁用用户
     * @param id
     * @return
     */
    @DeleteMapping
    public ResultInfo delete(Long id){
        //1.调用业务层停用
        Integer disabled = logService.disabled(id);
        //2.返回
        return ResultInfo.success(null);
    }

    /**
     * 更新用户
     * @param sysLog
     * @return
     */
    @PutMapping
    public ResultInfo update(@RequestBody SysLog sysLog){
        //1.调用业务层更新
        logService.update(sysLog);
        //2.返回
        return ResultInfo.success(null);
    }
}
